var $$ = jQuery.noConflict();
(function($, doc) {
    document.documentElement.style.fontSize = document.documentElement.clientWidth / 6.4 + 'px';
    $.init();
    $.ready(function() {
        //是否已经实名
        var realName=JSON.parse(localStorage.getItem('realName')) ;
        console.log(realName)
        if(realName.realName){
            $$('#send').css('display','none')
            $$('#name').val(realName.realName)
            $$('#idcard').val(realName.idCard)
            $$('#name').prop('readonly',true)
            $$('#idcard').prop('readonly',true)
        }
        //form表单
        $$('#send').on('touchend', function() {
            var i = 0;
            mui("#formData input").each(function() {
                if(!this.value || this.value.trim() == "") {
                    var label = this.previousElementSibling;
                    mui.alert(label.innerText + "不允许为空");
                    return false;
                } else {
                    i = i + 1
                }
            });
            if (i == 2) {
                if(/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test($$('#idcard').val())){
                    mui(this).button('loading');
                    $$('#send').prop('disabled','true')
                    $.post('/member/verified', {'name':$$('#name').val(),'idCard':$$('#idcard').val(),'type':'wechat'}, function (res) {
                        mui($$('#send')).button('reset');
                        $$('#send').prop('disabled','false')
                        if (res.code == 10008) {
                            mui.alert('实名认证成功!');
                            openPage('/wechat/toMain')
                        } else {
                            mui.alert(res.message);
                        }
                    })
                }else{
                    mui.alert('身份证格式不正确!');
                }
            }
        })
    });
})(mui, document);